//
//  MovieGridView.m
//  豆瓣
//
//  Created by dllo on 15/12/14.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "MovieGridView.h"

@implementation MovieGridView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)dealloc{
    [_nameLabel release];
    [_movieGridImageView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
    
}

- (void)createSubviews{
    
    self.movieGridImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 335 / 3, 150)];
    self.movieGridImageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_movieGridImageView];
    [_movieGridImageView release];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 335 / 3, 20)];
//    self.nameLabel.backgroundColor = [UIColor blackColor];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_nameLabel];
    [_nameLabel release];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.movieGridImageView addGestureRecognizer:tap];
    [tap release];
    
    self.movieGridImageView.userInteractionEnabled = YES;
    
    
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    NSInteger index = tap.view.tag - 1000;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    [self.myDelegate didSelectMovieGridView:self IndexPath:indexPath];
}


@end
